// promise.allSettled

Promise.myAllSettled = function(promises) {
    return new Promise((resolve, rejected) => {
        let len = promises.length
        let count = 0
        let result = []
        if(len == 0) {
            rejected()
        }

        for(let i = 0; i < len; i++) {
            Promise.resolve(promises[i]).then(
                res => {
                    result.push(res)
                    count += 1
                    if(count == len) {
                        resolve(result)
                    }
                },
                err => {
                    result.push(err)
                    count += 1
                    if(count == len) {
                        resolve(result)
                    }
                }
            )
        }
    }) 
}


var resolved = Promise.resolve(42);
var rejected = Promise.reject(-1);
var alsoRejected = Promise.reject(Infinity);

Promise.myAllSettled([resolved, rejected, alsoRejected]).then(function (result) {
  console.log(result); // 42
});

Promise.myAllSettled([rejected, alsoRejected]).catch(function (results) {
  console.log(results); // [-1, Infinity]
});